// local services - login, home page management

// display header - header elements must exist
chess_spider.local = {

// called after load!!
'init': function() {
	// save home page in state
	chess_spider.state.home_dom = 
		E.div( '#home',
			E.div( '#home_hdr',
			       	E.a( 'control', chess_spider.local.partShow, 'GO HERE!' ),
			       	E.a( 'sites', chess_spider.local.partShow, 'KOOL SITES' ),
			       	E.a( 'history', chess_spider.local.partShow, 'HISTORY' ),
			       	E.a( 'postings', chess_spider.local.partShow, 'POSTINGS' ) ),
			E.div( '#home_body', 'a.part:', 'replace me' ));
	// init home page in dom
	document.getElementById(chess_spider.params.home_pnt_id).replaceE( chess_spider.state.home_dom );
	chess_spider.local.partShow('control');
},

// deprecate this!
'displayHeader': function () {

	// if no login, nada
	if( !document.getElementById('cs__login') ) return;

	// todo: disable the movelist
	//=document.getElementById('home_body').enabled = false;

	// if logging in
	if( chess_spider.state.session.state == 'login' ) {
		document.getElementById('cs__login_tr').style.display = 'none';
		document.getElementById('cs__logout_tr').style.display = 'none';
		document.getElementById('cs__passwd_tr').style.display = 'table-row';
		document.getElementById('cs__email_tr').style.display = 'none';
	}
	// if email
	else if( chess_spider.state.session.state == 'email' ) {
		document.getElementById('cs__login_tr').style.display = 'none';
		document.getElementById('cs__logout_tr').style.display = 'none';
		document.getElementById('cs__passwd_tr').style.display = 'none';
		document.getElementById('cs__email_tr').style.display = 'table-row';
	}
	// logged in
	else if( chess_spider.state.user.login_ts ) {
		document.getElementById('cs__logout_tr').cells[1].innerHTML = "<small>WELCOME</small> "+chess_spider.state.user.name;
		document.getElementById('cs__login_tr').style.display = 'none';
		document.getElementById('cs__logout_tr').style.display = 'table-row';
		document.getElementById('cs__passwd_tr').style.display = 'none';
		document.getElementById('cs__email_tr').style.display = 'none';
	}
	// logged out
	else if( !chess_spider.state.user.login_ts ) {
		document.getElementById('cs__login_tr').style.display = 'table-row';
		document.getElementById('cs__logout_tr').style.display = 'none';
		document.getElementById('cs__passwd_tr').style.display = 'none';
		document.getElementById('cs__email_tr').style.display = 'none';
	}
},

// modal popup
'popup_dom': function() { return document.getElementById('cs__popup'); },
'popup': function( Eguts ) {
	var pnt = document.getElementById(chess_spider.params.home_pnt_id);

	// disable - for movelists and fixedboards, gray out, disable input
	(chess_spider.FixedBoard.fixedboards().concat( chess_spider.MoveList.movelists() )).forEach( function(el){
		console.log( 'disable: '+el.dom_div.className );
		el.dom_div.setAttribute('cs__disabled',true);
	} );
	
	// if already exists, replace innards
	if( chess_spider.local.popup_dom() )  chess_spider.local.popup_dom().replaceE( Array.prototype.slice.call(arguments) );
	
	// create new popup, set top
	else {
		document.body.appendChild( E.div( '#cs__popup', Array.prototype.slice.call(arguments) ) );
		chess_spider.local.popup_dom().style.top = (pnt.offsetTop * 0.66);
	}

	// redo width
	chess_spider.local.popup_dom().style.left = ((document.body.clientWidth-chess_spider.local.popup_dom().offsetWidth)/2);
},
// popup that clears itself in x ms
'timedPopup': function( ms ) {
	chess_spider.local.popup( Array.prototype.slice.call(arguments,1) );
	setTimeout( chess_spider.local.popout, ms );
},
// popout
'popout': function() {
	// re-enable - for movelists and fixedboards, gray out, disable input
	(chess_spider.FixedBoard.fixedboards().concat( chess_spider.MoveList.movelists() )).forEach( function(el){
			el.dom_div.removeAttribute('cs__disabled');
	} );

	// remove popup
	if( chess_spider.local.popup_dom() ) chess_spider.local.popup_dom().parentNode.removeChild( chess_spider.local.popup_dom() );
},

'loginStart': function(e) {
	e.stopPropagation(); e.preventDefault(); 
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;
	//-chess_spider.local.displayHeader();
	chess_spider.local.popup( E.h4( 'Enter Login and Password to Log into Chess Spider...' ),
				"Login ", E.input(), " \u000a Password ", E.password(),
				E.br(),
				E.button( chess_spider.local.loginSubmit, 'LOGIN' ),
				"\u000a",
				E.button( chess_spider.local.loginCancel, 'Cancel' ),
				"\u000a",
				E.button( chess_spider.local.loginEmail, 'I Forgot' ) );
},
'loginCancel': function(e) {
	e.stopPropagation(); e.preventDefault();
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;
	chess_spider.local.popout();
},
'loginEmail': function(e) {
	e.stopPropagation(); e.preventDefault();
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;
	chess_spider.local.popup( E.h4( 'Please send Chess Spider your email...' ),
			'Email ', E.input( 's.width:44ex' ),
			E.br(),
			E.button( chess_spider.local.loginStart, 'Login' ),
			"\u000a",
			E.button( chess_spider.local.loginCancel, 'Cancel' ),
			"\u000a",
			E.button( chess_spider.local.loginEmailSubmit, 'SEND' ) );
},
'logoutStart': function(e) {
	e.stopPropagation(); e.preventDefault();
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;
	if( chess_spider.state.session.login ) logoutSubmit(); 
	else chess_spider.local.timedPopup( 2500, E.h4( 'You are Not Currently Logged into Chess Spider' ), 'Sorry, you cannot log out...' );
},
'loginSubmit': function(e) {
	e.stopPropagation(); e.preventDefault(); 
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;
	var login = e.target.parentNode.getElementsByTagName('input')[0].value;
	var cancel = e.target.parentNode.getElementsByTagName('input')[1].value;
	if( !login || login.length<4 ) {
		nonblockAlert( 'You must enter Login' );
		e.target.parentNode.getElementsByTagName('input')[0].focus();
		return;
	}
	if( !cancel || cancel.length<4 ) {
		nonblockAlert( 'You must enter Password' );
		e.target.parentNode.getElementsByTagName('input')[1].focus();
		return;
	}
	chess_spider.Message.login( login, cancel, chess_spider.local.loginSuccess, chess_spider.local.loginFailure );
},
'loginSuccess': function() {
	console.log( 'login success' );
	chess_spider.local.timedPopup( 1500, E.h4( 'Welcome '+chess_spider.state.user.name ), 'You have successfully logged in' );
	//todo: show in header
},
'loginFailure': function() {
	console.log( 'login failure' );
	chess_spider.local.popup( E.h4( 'Unable to Log In to Chess Spider' ),
				'Your login or password were incorrect', 
				E.br(),
				E.button( chess_spider.local.loginStart, 'Login' ),
				" \u000a ",
				E.button( chess_spider.local.loginCancel, 'Cancel' ),
				" \u000a ",
				E.button( chess_spider.local.loginEmail, 'I Forgot' ) );
},
'loginInit': function(e) {
	e.stopPropagation(); e.preventDefault(); 
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;
	chess_spider.loginCancel(e);
	chess_spider.Message.init();
},
'logoutSubmit': function(e) { chess_spider.Message.logout();
	e.stopPropagation(); e.preventDefault(); 
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;
},
'loginEmailSubmit': function(e) { chess_spider.Message.loginEmail();
	e.stopPropagation(); e.preventDefault(); 
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;
},

'home': function(e) {

	if( !e ) e = window.event;
	e.stopPropagation(); e.preventDefault(); 
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;

	// already home (might change later for dynamic home)
	if( chess_spider.state.home ) return;

	// if no home_dom, then nothing to do
	if( !chess_spider.state.home_dom ) return;

	// restore home
	document.getElementById(chess_spider.params.home_pnt_id).replaceE( chess_spider.state.home_dom );
	console.log( 'home dom replaced' );
},

// this might be called regularly or via Event
'partShow': function( part ) {

	// if coming from event
	if( part instanceof Event ) {
		var e = window.event;
		part = e.target.href.match(/([a-z]*)$/)[1];
		e.stopPropagation(); e.preventDefault();
	}

	// current
	var cur_dom = document.getElementById('home_body');
	cur_dom.style.webkitTransform = "rotate(180deg) scale(0.1)";
	setTimeout( step2, 500 );

	function step2() {
		// replace node with part
		cur_dom.replaceE( chess_spider.local[part]() );
		cur_dom.style.webkitTransform = "rotate(0deg) ";
	}
},

// return control dom
'control': function() { return E.div( '.ctl', 
		E.div( '.ctl_out', 
			E.div( '.ctl_in', E.div( '.ctl_hdr', 'Chess Spider', E.ul(
				E.a( 'login', chess_spider.local.loginStart, 'Login to Chess Spider' ),
				E.a( 'subscribe', chess_spider.local.loginEmail, 'Subscribe to CS' ),
				E.a( 'save-server', chess_spider.local.save, 'Save Your Work to CS' ),
				E.a( 'save-publish', chess_spider.local.save, 'Publish as Chess Spider Page' ),
				E.a( 'logout', chess_spider.local.logoutStart, {'enabled':false}, 'Log Out of Chess Spider' )
				) ) ),
			E.div( '.ctl_in', E.div( '.ctl_hdr', 'Help! hElp! heLp! helP!', E.ul(
				E.a( 'help-start', chess_spider.local.help, 'How do I start a new game?' ),
				E.a( 'help-save', chess_spider.local.help, 'How do I save what I have?' ),
				E.a( 'help-keyboard', chess_spider.local.help, 'What are the Keyboard Shortcuts?' ),
				E.a( 'help-create', chess_spider.local.help, 'I can create my own web pages?' ),
				E.a( 'help-subscribe', chess_spider.local.help, 'What is a CS Subscription?' ),
				E.a( 'help-use', chess_spider.local.help, 'How can I use CS on my site?' )
				) ) ),
			E.div( '.ctl_in', E.div( '.ctl_hdr', 'Chess Spider Technical', E.ul(
				E.a( 'http://code.google.com/p/chess-spider/issues/list', null, 'Review / Pull  CS Code' ),
				E.a( 'http://code.google.com/p/chess-spider/issues/list', null, 'Report a Chess Spider Bug' ),
				E.a( 'contact', chess_spider.local.contact, 'Contact Us Here' ) ) ) ) ),
		E.div( '.ctl_out',
			E.div( '.ctl_in', E.div( '.ctl_hdr', 'Start New Game, Load New PGN', E.ul(
				E.a( 'virgin', chess_spider.local.virgin, 'Start with a New Board' ),
				E.a( 'puzzle', chess_spider.local.puzzle, 'Set up Pieces on Board' ),
				E.a( 'null', null, 'Load Board from PGN on Web' ),
				E.a( 'null', null, 'Load from PGN on Your Computer' ) ) ) ),
			E.div( '.ctl_in', E.div( '.ctl_hdr', 'Save, Export or Publish', E.ul(
				E.a( 'null', null, 'Save Your Work (Local or to CS)' ),
				E.a( 'null', null, 'Export PGN File of Your Work' ),
				E.a( 'null', null, 'Make Your Work into a Web Page' ) ) ) ),
			E.div( '.ctl_in', E.div( '.ctl_hdr', 'Chess Spider Controls', E.ul(
				E.a( 'null', null, 'Set the Font to Use for Move Lists' ),
				E.a( 'null', null, 'Set the Symbol/Font to Use for Board' ),
				E.a( 'null', null, 'Turn On/Off Keyboad Short Cuts' ) ) ) )
			) );
},

// return sites
'sites_dom': null,
'sites': function() {

	// if no sites, pull from server
	if( !chess_spider.local.sites_dom ) {

		chess_spider.local.sites_dom = document.createElement('div');
		chess_spider.local.sites_dom.className = 't';

		new chess_spider.Message( 'sites', {}, null, parseData, null );

		function parseData(message) {

			for( var i=0, stt=null, stt_nm=null, site=null; i<message.result.rows.length; i++ ) {

				var r = message.result.rows[i];

				// new stt - site type
				if( stt_nm != r.stt_nm ) {

					// if t0 exists, write to dom
					if( stt ) chess_spider.local.sites_dom.appendChild( stt );

					// start new t0
					stt = document.createElement('div');
					stt.className = 'stt';
					stt.appendChild( document.newElement('div',{'class':'stt_nm'},r.stt_nm) );
					stt.appendChild( document.newElement('div',{'class':'sits'},null) );
					if( r.stt_desc ) stt.lastChild.appendChild( document.newElement('div',{'class':'stt_desc'}),r.stt_desc);
				}
				
				// append site
				stt.lastChild.appendChild( document.newElement('div',{'class':'sit_nm'}, "<a href='"+r.url+"'>"+r.sit_nm+"</a>"));
				stt.lastChild.appendChild( document.newElement('div',{'class':'sit_desc'}, r.sit_desc) );
			}

			// if stt, append
			if( stt ) chess_spider.local.sites_dom.appendChild( stt );
		}
	}

	return chess_spider.local.sites_dom;
},

// return history
'history_dom': document.createElement('DIV'),
'history': function() {
	this.history_dom.className = 't';
	this.history_dom.innerHTML = ''
		+"<div class='t0'>"
		+"	<div class='t1'>Internet Cool Games</div>"
		+"	<div class='t2'>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"	</div>"
		+"</div>"
		+"<div class='t0'>"
		+"	<div class='t1'>Look at This</div>"
		+"	<div class='t2'>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"	</div>"
		+"</div>"
		+"<div class='t0'>"
		+"	<div class='t1'>Look at This</div>"
		+"	<div class='t2'>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"	</div>"
		+"</div>"
		+"<div class='t0'>"
		+"	<div class='t1'>Look at This</div>"
		+"	<div class='t2'>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"	</div>"
		+"</div>"
		+"</div>";
	return this.history_dom;
},

// return postings
'postings_dom': document.createElement('DIV'),
'postings': function() {
	this.postings_dom.className = 't';
	this.postings_dom.innerHTML = ''
		+"<div class='t0'>"
		+"	<div class='t1'>Internet Cool Games</div>"
		+"	<div class='t2'>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"	</div>"
		+"</div>"
		+"<div class='t0'>"
		+"	<div class='t1'>Look at This</div>"
		+"	<div class='t2'>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"	</div>"
		+"</div>"
		+"<div class='t0'>"
		+"	<div class='t1'>Look at This</div>"
		+"	<div class='t2'>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"	</div>"
		+"</div>"
		+"<div class='t0'>"
		+"	<div class='t1'>Look at This</div>"
		+"	<div class='t2'>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"		<div class='t3'>Long title for the selections beneath this div</div>"
		+"		<div class='t4'>Title for First Selection in this Div</div>"
		+"		<div class='t5'>re aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire aofire</div>"
		+"	</div>"
		+"</div>"
		+"</div>";
	return this.postings_dom;
},

'puzzle': function(e) {
	e.stopPropagation(); e.preventDefault(); 
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;
	chess_spider.FixedBoard.setupInit(true); },
'virgin': function(e) {
	e.stopPropagation(); e.preventDefault(); 
	if( e.target.ancestorByAttribute('cs__disabled','true',true) ) return;
	chess_spider.FixedBoard.setupInit(false); },

'test1': function() {
	nonblockAlert( 'rand = ' + chess_spider.state.session.rand + '\n'
			+'hash = ' + chess_spider.state.session.hash + '\n'
			+'sum = ' + (0+chess_spider.state.session.rand+chess_spider.state.session.hash) + '\n'
			+'msg = ' + 'in the room the women' + '\n'
			+'encode = '+nonce64.encode( 'in the room the women', (0+chess_spider.state.session.rand+chess_spider.state.session.hash) )
		     );
	e.stopPropagation(); e.preventDefault();
},
'test2': function() {
	nonblockAlert( 'http://chess-spider.net/.encode?'
			+ escape(nonce64.encode(
					JSON.stringify( {'msg':'in the room the women'} ),
					(0+chess_spider.state.session.rand+chess_spider.state.session.hash) )
			) );
	e.stopPropagation(); e.preventDefault();
},
'test3': function() {
	nonblockAlert( 'sending test message\nmary plus lamb' );
	new chess_spider.Message( 'encode',
			{ 'mary':'had a little lamb', 'lamb':'fleece was white as snow' },
			{ 'bob':'had a little monkey', 'lamb':'fleece was black as soot' },
			function( message ) { nonblockAlert( JSON.stringify(message.result) ); },
			null );
	e.stopPropagation(); e.preventDefault();
}

};
